import java.io.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-08-15
 * Time: 14:31
 */
public class demo9 {
    public static void main1(String[] args) {
        try (Reader reader = new FileReader("./test.txt")) {
//            reader.read();一次读取一个字符,返回值int
//            reader.read(char[] cbuf);一次IO把字符填充到字符数组中,返回实际读取到的个数(int)
//            reader.read(char[] cbuf,int off,int len);把字符填充到数组的[off,off+len)范围
            while (true) {
                int n = reader.read();
                if (n == -1) {
                    break;
                }
                char ch = (char) n;
                System.out.println(ch);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
//            writer.write(int c);写一个字符
//            writer.write(String str);写一个字符串
//            writer.write(String str,int off,int len);将字符串的[off,off+len)的范围的内容写入文件中
//            writer.write(char[] cbuf);写入字符数组中的内容
//            writer.write(char[] cbuf,int off,int len);写入字符数组中[off,off+len)的范围的内容
        try (Writer writer = new FileWriter("./test.txt", true)) {
//            writer.write("你好啊");
            String s = new String("我是傻逼");
            writer.write(s, 0, 2);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
